//
//  MyBackBar.m
//  MyCloud
//
//  Created by Visitor on 7/14/13.
//  Copyright (c) 2013 visitor.zc@gmail.com. All rights reserved.
//

#import "MyBackBar.h"

@implementation MyBackBar
@synthesize delegate = _delegate;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (id)initWithTitle:(NSString *)title andType:(int)type
{
    self = [super init];
    if(self)
    {
        //self.backgroundColor = [UIColor greenColor];
        UIImageView *background = [[UIImageView alloc] initWithFrame:self.frame];
        background.image = [UIImage imageNamed:@"tabBar.png"];
        [self addSubview:background];
        [background release];

        // BackImageVIew
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Btn_back.jpg"]];
        imageView.frame = CGRectMake(0, 0, 60, 44);
        imageView.userInteractionEnabled = YES;
        [self addSubview:imageView];
        [imageView release];
        
        UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backImageClick)];
        [imageView addGestureRecognizer:tgr];
        [tgr release];
        
        // TitleLabel
        UILabel *label = [[UILabel alloc] init];
        if(type == 1)
        {
            label.frame = CGRectMake(80, 0, 240, 44);
        }
        else
        {
            label.frame = self.bounds;
            label.textAlignment = NSTextAlignmentCenter;
        }
        label.text = title;
        label.backgroundColor = [UIColor clearColor];
        [self addSubview:label];
        [label release];
        [self sendSubviewToBack:label];
        
        
    }
    return self;
}

- (void)backImageClick
{
    [_delegate backImageClick];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
